package com.fastloan.mgt.invest.controller.value;

import com.alibaba.fastjson.JSON;
import com.fastloan.mgt.invest.model.InvestCusTemp;
import com.fastloan.mgt.invest.model.InvestCustomer;
import com.fastloan.mgt.invest.model.InvestValue;
import com.fastloan.mgt.invest.model.vo.WorldCusVo;
import com.fastloan.mgt.invest.service.InvestCusTempService;
import com.fastloan.mgt.invest.service.InvestValueService;
import com.kawins.base.baseabs.BaseController;
import com.kawins.result.ResultTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 问卷回答结果
 *
 * @author rankai
 *         createTime 2017-08-2017/8/8 10:39
 */
@RestController
@RequestMapping("/api/invest/value")
public class InvestValueController extends BaseController<InvestValue> {

    @Autowired
    private InvestValueService investValueService;

    @Autowired
    private InvestCusTempService investCusTempService;

    /**
     * 增加值
     *
     * @param request        HttpServletRequest
     * @param investCustomer 客户信息Bean
     * @param managerId      模版ID
     * @param tempId         tempId
     * @return
     */
    @PostMapping("/submit/{tempId}/{managerId}/{typeId}/{subjectId}")
    public ResultTo insert(HttpServletRequest request, InvestCustomer investCustomer,
                           @PathVariable("managerId") String managerId,
                           @PathVariable("tempId") String tempId,
                           @PathVariable("typeId") String typeId,
                           @PathVariable("subjectId") String subjectId) {
        Map<String, Object> map = investValueService.insertValue(request, investCustomer, managerId, tempId, typeId, subjectId);
        ResultTo resultTo = new ResultTo().setData("code", 200).setData("msg", "success").setData("data", map);
        log.debug("收到调查问卷,{}", JSON.toJSONString(resultTo));
        return resultTo;
    }

    /**
     * 根据用户值Id导出world
     *
     * @param cusValueId 根据用户值Id
     * @param subjectId  项目Id
     * @param response   HttpServletResponse
     * @param request    HttpServletRequest
     * @return
     */
    @GetMapping("/{subjectId}")
    public void worldByCusValueId(HttpServletResponse response, HttpServletRequest request,
                                  @PathVariable("subjectId") String subjectId,
                                  @RequestParam(value = "cusValueId", required = false) String cusValueId) {
        investValueService.worldBySubject(cusValueId, subjectId, request, response);
    }

    /**
     * 页面预览客户提交的调查问卷
     *
     * @param cusValueId 客户问卷ID
     * @return
     */
    @GetMapping("/show/{cusValueId}")
    public ResultTo showCusValue(@PathVariable(value = "cusValueId") String cusValueId) {
        WorldCusVo worldCusVo = investValueService.showCusValue(cusValueId);
        return new ResultTo().setData(worldCusVo);
    }

    /**
     * 根性问卷信息
     *
     * @param investCusTemp 问卷信息Bean
     * @return
     */
    @PutMapping("/cusTemp")
    public ResultTo updateCusTemp(InvestCusTemp investCusTemp) {
        investCusTempService.updateByPrimaryKeySelective(investCusTemp);
        return new ResultTo();
    }

}
